# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.spark_sql_operator import SparkSqlOperator

from jms.dwd.tab.dwd_tab_barscan_collect_base_dt import jms_dwd__dwd_tab_barscan_collect_base_dt
from jms.dwd.tab.dwd_tab_barscan_sign_base_dt import jms_dwd__dwd_tab_barscan_sign_base_dt
from jms.dwd.tab.dwd_tab_barscan_taking_base_dt import jms_dwd__dwd_tab_barscan_taking_base_dt
from jms.dwd.sqs.dwd_sqs_registration_problem_piece_base_dt import jms_dwd__dwd_sqs_registration_problem_piece_base_dt
from jms.dwd.January.dwd_work_order_dt import jms_dwd__dwd_work_order_dt
from jms.dwd.oms.dwd_yl_oms_oms_waybill_incre_dt import jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
from jms.dim.dim_lmdm_sys_area import jms_dim__dim_lmdm_sys_area
from jms.time_sensor.time_after_09_30 import time_after_09_30

jms_ai_group__complaints_dim_citypair_dt = SparkSqlOperator(
    task_id='jms_ai_group__complaints_dim_citypair_dt',
    email=['jarl.huang@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    name='jms_ai_group__complaints_dim_citypair_dt_{{ execution_date | date_add(1) | cst_ds }}',
    email_on_retry=True,
    retries=1,
    sql='jms/aigroup/ai_group/complaints_dim_citypair_dt/execute.sql',
    yarn_queue='pro',
    driver_memory='4G',
    driver_cores=4,
    executor_memory='16G',
    executor_cores=2,
    pool_slots=2,
    pool='unlimited_pool',
    num_executors=30,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.executor.memoryOverhead': '5G',
          'spark.dynamicAllocation.enabled': 'true',
          'spark.shuffle.service.enabled': 'true',
          'spark.dynamicAllocation.maxExecutors': 50,
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',
          'spark.dynamicallocation.enabled': 'true',
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,
          'spark.sql.shuffle.partitions': 400,
          'spark.port.maxRetries': 100
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 5000,
              'hive.exec.max.dynamic.partitions': 30000
              },
    execution_timeout=timedelta(hours=2),
    priority_weight=20,
)  # type: SparkSqlOperator

jms_ai_group__complaints_dim_citypair_dt << [
    jms_dwd__dwd_tab_barscan_collect_base_dt,
    jms_dwd__dwd_tab_barscan_sign_base_dt,
    jms_dwd__dwd_tab_barscan_taking_base_dt,
    jms_dwd__dwd_yl_oms_oms_waybill_incre_dt,
    jms_dwd__dwd_sqs_registration_problem_piece_base_dt,
    jms_dwd__dwd_work_order_dt,
    jms_dim__dim_lmdm_sys_area,
    time_after_09_30

]
